package com.nuotu.datawall.clouddata.util;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.kongzue.dialog.interfaces.OnDialogButtonClickListener;
import com.kongzue.dialog.util.BaseDialog;
import com.kongzue.dialog.util.TextInfo;
import com.kongzue.dialog.v3.MessageDialog;
import com.nuotu.datawall.clouddata.layoutData.BasicDataLayout;

import org.xutils.x;

import java.util.Timer;
import java.util.TimerTask;

import static com.kongzue.dialog.util.DialogSettings.blurAlpha;

public class MessageDialogUtil {

    private static MessageDialog netErrorDialog;
    private static Timer timer;

    private   int netError=30;
    public static MessageDialogUtil getInstance(Context context) {
        return new MessageDialogUtil();
    }
    private  MessageOnDialogButtonClickListener messageOnDialogButtonClickListener;

    public   MessageDialog showNetError(Context context){
        timer=new Timer();
        netErrorDialog= MessageDialog.show((AppCompatActivity) context, "网络连接", "当前设备无网络!", "重试（30）");
        netErrorDialog.setMessageTextInfo(new TextInfo().setFontColor(Color.RED).setFontSize(45));
        netErrorDialog.setTitleTextInfo(new TextInfo().setFontColor(Color.RED).setFontSize(40));
        netErrorDialog.setButtonPositiveTextInfo(new TextInfo().setFontSize(36));
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                x.task().post(new Runnable() {
                    @Override
                    public void run() {
                        netErrorDialog.setOkButton("重试（"+netError+"）");
                    }
                });
                netError--;
                if(netError<=0){
                    timer.cancel();
                    timer.purge();
                    timer =null;
                    messageOnDialogButtonClickListener.onRefresh();
                }
            }
        },0,1000);
        return netErrorDialog;
    }
    public  MessageDialog setNetError(int netError) {
        this.netError = netError;
        return netErrorDialog;
    }
    public void setMessageOnDialogButtonClickListener(MessageOnDialogButtonClickListener messageOnDialogButtonClickListener) {
        this.messageOnDialogButtonClickListener = messageOnDialogButtonClickListener;
    }
    public interface MessageOnDialogButtonClickListener extends  OnDialogButtonClickListener{
        public void onRefresh();
    }

}
